package com.nh.alarm;

import java.util.concurrent.ConcurrentLinkedQueue;


public class AcsAlarmThread extends Thread {
    private static AcsAlarmThread instance = new AcsAlarmThread();
    private boolean stopped;
    private ConcurrentLinkedQueue<ACSEventAlarm> messageQueue;

    private AcsAlarmThread() {
        stopped = false;
        messageQueue = new ConcurrentLinkedQueue<>();
    }

    public void setStopped(boolean stopped) {
        synchronized (this) {
            this.stopped = stopped;
        }
    }

    public static AcsAlarmThread getInstance() {
        return instance;
    }

    public void addMessage(ACSEventAlarm msg) {
        messageQueue.offer(msg);
    }

    private ACSEventAlarm removeMessage() {
        return messageQueue.poll();
    }

    @Override
    public void run() {
        while (!stopped) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

//            System.out.println("messageQueue size = " + messageQueue.size());
            if (messageQueue.isEmpty()) {
                continue;
            }

            ACSEventAlarm acsEventAlarm = removeMessage();
//            HttpClientHelper.uploadAlarm(acsEventAlarm);
        }
    }
}
